package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import cn.sumpu.app.guoguojie.dao.AuxTestDao;
import cn.sumpu.app.guoguojie.domain.AuxTest;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class AuxTestDaoImpl extends SqlSessionDaoSupport implements AuxTestDao {

	private static Logger logger = LoggerFactory.getLogger(AuxTestDaoImpl.class);

	public void insertBatch(List<AuxTest> testList) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("cn.sumpu.app.guoguojie.persistence.AuxTestMapper.insertBatch",
							testList);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Write database failure.", e);
			}
			throw new AppBusinessException("Write database failure.", e);
		}
	}

	public void insert(AuxTest test) throws AppBusinessException {
		try {
			getSqlSession().insert(
					"cn.sumpu.app.guoguojie.persistence.AuxTestMapper.insert",
					test);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Write database failure.", e);
			}
			throw new AppBusinessException("Write database failure.", e);
		}
	}

	public void delete(AuxTest test) throws AppBusinessException {
		try {
			getSqlSession().delete(
					"cn.sumpu.app.guoguojie.persistence.AuxTestMapper.delete",
					test);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Write database failure.", e);
			}
			throw new AppBusinessException("Write database failure.", e);
		}
	}

	public void update(AuxTest test) throws AppBusinessException {
		try {
			getSqlSession().update(
					"cn.sumpu.app.guoguojie.persistence.AuxTestMapper.update",
					test);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Write database failure.", e);
			}
			throw new AppBusinessException("Write database failure.", e);
		}
	}

	public AuxTest query(AuxTest test) throws AppBusinessException {
		try {
			return (AuxTest) getSqlSession().selectOne(
					"cn.sumpu.app.guoguojie.persistence.AuxTestMapper.select",
					test);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Read database failure.", e);
			}
			throw new AppBusinessException("Read database failure.", e);
		}
	}

	@Override
	public void deleteAll() throws AppBusinessException {
		try {
			getSqlSession().update(
					"cn.sumpu.app.guoguojie.persistence.AuxTestMapper.deleteAll");
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Write database failure.", e);
			}
			throw new AppBusinessException("Write database failure.", e);
		}
	}

}
